<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class GoodExample extends Model
{
    protected  $table='good_example';

    protected $fillable = [
        'org_id',
        'name',
        'avatars',
        'political_affiliation',
        'workplace',
        'publish_time',
        'status',
        'abstracts',
        'description'
    ];

    public function getPublishTimeAttribute() {
        if (isset($this->attributes['publish_time'])) {
            $date = new Carbon($this->attributes['publish_time']);
            return $date->getTimestamp();
        }

        return null;
    }

    public function setPublishTimeAttribute($value) {
        if (!isset($value) || empty($value)) {
            return;
        }

        $date = new Carbon();
        $date->setTimestamp($value);
        $this->attributes['publish_time'] = $date->toDateTimeString();
    }
}
